import React from 'react';
import {
  View,
  TouchableOpacity,
  Text,
} from 'react-native';
import CommonListPage from '../common/CommonListPage';
import TImage from '../../components/TImage';
import BaseItem from '../common/BaseItem';
import SizeUtils from '../../common/SizeUtils';
import Config from '../../config';
import GuahaoConstants from './GuahaoConstants';
// import GuahaoRequestHospitalListAction from '../../actions/guahao/GuahaoRequestHospitalListAction';

export default class GuahaoHospitalListPage extends CommonListPage {
  constructor(props) {
    super(props);

    this._useLoadMore = false;
    this._noEmpty = true;
    this._gotoItem = false;

    this._dataKey = "key";
  }

  componentDidMount() {

  }

  _dealEnterPage() {
    if(this._gotoItem == true) {
      this._gotoItem = false;
      return;
    }
    if(this._listView != null){
      this._listView.doRefresh();
    }
  }

  _getTitle() {
    return this.props.pageData.routeData.buttonData.name + "医院";
  }

  _onPressItem(data) {
    this._gotoItem = true;
    if(data.url) {
      this.gotoPage(Config.pages.guahao_hospital_web, {buttonData:data});
    }
    else if (data.erweima) {
      this.gotoPage(Config.pages.guahao_erweima, {buttonData:data});
    }
  }

  _onRenderItem(data, index) {
    return (<Item data={data} index={index} />)
  }

  // _getListViewStyle() {
    // return {
    //     width:SizeUtils.getWindowSize().width,
    //     height:(SizeUtils.getWindowSize().height - Config.paddingTop - SizeUtils.translateDesignHeightToCode(40)),
    //     backgroundColor:"#ffffff00"};
  // }

  _requestData(page, listView) {
    // new GuahaoRequestListAction().call(this, {})
    this._timer = setTimeout(() => {
      clearTimeout(this._timer);
      listView.finish(1, GuahaoConstants.LIST[this.props.pageData.routeData.buttonData.key]);
    }, 1000);
  }
}

class Item extends BaseItem {
  constructor(props) {
    super(props);
  }

  render() {
    return (
      <View style={{flex:1, paddingTop:SizeUtils.translateDesignHeightToCode(40),
          paddingBottom:SizeUtils.translateDesignHeightToCode(40), backgroundColor:"#ffffff",
          height:SizeUtils.translateDesignHeightToCode(200), flexDirection:"row",
          justifyContent:"space-between",
          alignItems:"center", borderColor:"#eeeeee", borderBottomWidth:SizeUtils.translateDesignNumToCode(3)}}>
        <View style={{flexDirection:"row", justifyContent:"space-between",
          alignItems:"center"}}>
          <TImage source={this.props.data.imageUrl} style={{width:120, height:120}}/>
          {this._renderRightContent()}
        </View>
        <TImage source={require("../../../resource/images/common/Back-icon.png")}
          style={{transform:[{scaleX:-1}], width:20, height:35}} />
      </View>
    )
  }

  _renderRightContent() {
    return (
      <View style={{flex:1, paddingLeft:SizeUtils.translateDesignWidthToCode(40)}}>
        <Text style={{fontSize:SizeUtils.translateFontSizeToCode(30)}}>
          {this.props.data.name}
        </Text>
        <Text style={{fontSize:SizeUtils.translateFontSizeToCode(26), color:"#999999",
            paddingTop:SizeUtils.translateDesignHeightToCode(38)}}>
          {this.props.data.description}
        </Text>
      </View>
    )
  }
}
